const arr = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];
function Find(target, array) {
  let x = array.length - 1;
  let y = 0;
  while (y <= 2 && x >= 0) {
    if (array[x][y] > target) {
      x--;
    } else if (array[x][y] < target) {
      y++;
    } else {
      return true;
    }
  }
  return false;
}

console.log(Find(7, arr));

const arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
// 必须是排好序的
function binarySearch(target, arr, left, right) {
  if (left > right) {
    return -1
  }
  const mid = Math.floor((left + right) / 2);
  if (arr[mid] === target) {
    return mid;
  }

  if (arr[mid] > target) {
    return binarySearch(target, arr, left, mid - 1);
  }
  if (arr[mid] < target) {
    return binarySearch(target, arr, mid + 1, right);
  }
}

console.log(binarySearch(9, arr2, 0, arr2.length));
